package com.xframe.domain.views;

import com.xframe.domain.role.IUserCredentials;
import com.xframe.domain.sys.SysModel;
import com.xframe.domain.sys.SysModelConfig;
import com.xframe.domain.views.builder.*;
import java.util.ArrayList;
import java.util.List;

public class ModelConfigViewBuilderRunTime {


    public static List<IModelConfigBuilder> createUIBuilder(){
        List<IModelConfigBuilder> modelConfigBuilderList = new ArrayList<>();
        modelConfigBuilderList.add(new QueryUIModelBuilder());
        modelConfigBuilderList.add(new TableUIModelBuilder());
        modelConfigBuilderList.add(new ViewUIModelBuilder());
        modelConfigBuilderList.add(new FormByAddUIModelBuilder());
        modelConfigBuilderList.add(new FormByEditUIModelBuilder());
        return modelConfigBuilderList;
    }

    public static List<IModelConfigBuilder> createModelConfigBuilder(){
        List<IModelConfigBuilder> modelConfigBuilderList = new ArrayList<>();
        modelConfigBuilderList.add(new ModelConfigBuilder());
        modelConfigBuilderList.add(new ModelBySelectConfigBuilder());
        modelConfigBuilderList.add(new ModelByRefConfigBuilder());
        modelConfigBuilderList.add(new ModelFullConfigBuilder());
        modelConfigBuilderList.add(new ModelByExportConfigBuilder());
        modelConfigBuilderList.add(new ModelByExportRefConfigBuilder());
        return modelConfigBuilderList;
    }

    public static List<SysModelConfig> builderView(SysModel sysModel, IUserCredentials userCredentials){
        List<IModelConfigBuilder> modelConfigBuilderList = createUIBuilder();
        List<SysModelConfig> modelConfigList = new ArrayList<>();
        for(IModelConfigBuilder viewBuilder : modelConfigBuilderList){
            List<SysModelConfig> sysModelConfigs = viewBuilder.builder(sysModel,userCredentials);
            modelConfigList.addAll(sysModelConfigs);
        }
        return modelConfigList;
    }

    public static List<SysModelConfig> builderConfig(SysModel sysModel, IUserCredentials userCredentials){
        List<IModelConfigBuilder> modelConfigBuilderList = createModelConfigBuilder();
        List<SysModelConfig> modelConfigList = new ArrayList<>();
        for(IModelConfigBuilder viewBuilder : modelConfigBuilderList){
            List<SysModelConfig> sysModelConfigs = viewBuilder.builder(sysModel,userCredentials);
            modelConfigList.addAll(sysModelConfigs);
        }
        return modelConfigList;
    }
}
